Skip to content

fix: scale nested namespace declarations linearly - #33

Merged
nikku merged 1 commit into
mainfrom
fix-namespace-declaration-dos
Sep 21, 2026
Merged

nikku merged 1 commit into
mainfrom
fix-namespace-declaration-dos

Conversation

@nikku

@nikku nikku commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Proposed Changes

Fixes the quadratic blow-up behind GHSA-6w8c-5m3c-g2m8: with namespace processing enabled, every element declaring an xmlns prefix cloned the entire namespace matrix, and every open element kept its parent matrix alive on a stack. A document nested to depth N with per-level declarations cost O(N²) time and memory — a ~120KB payload exhausted the heap with an uncatchable V8 fatal error.

Approach: replace clone-on-write with a single mutable matrix plus a per-element undo log (restored when the element closes), making time and memory linear in nesting depth. The el.ns proxy getter now exposes a snapshot, copied on access and cached until the matrix changes, so captured references keep their former immutability semantics (moddle-xml captures obj.ns).

The per-matrix element name cache (stored under a matrix symbol) could not survive a shared mutable matrix — it is now rebuilt whenever the matrix changes, and a regression test covers repeated tag names across shadowed scope boundaries.

Verified: advisory PoC depth 3000 goes from fatal OOM to ~40ms/7MB; depth 50000 parses linearly. Event streams are byte-identical pre/post on prefix-shadowing and streaming scenarios; full suite (192 tests) and perf parity pass.

Related to GHSA-6w8c-5m3c-g2m8

Steps to try out:

npx @bpmn-io/sr nikku/saxen#fix-namespace-declaration-dos -c "npm ci && npm test"

Checklist

Ensure you provide everything we need to review your contribution:

  • Contribution meets our definition of done
  • Pull request establishes context
    • Link to related issue(s), i.e. Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}
    • Brief textual description of the changes
    • Screenshots or short videos showing UI/UX changes
    • Steps to try out, i.e. using the @bpmn-io/sr tool

Every element declaring an xmlns prefix cloned the whole namespace
matrix, and every open element kept its parent matrix alive on a
stack. A document nested to depth N with per-level declarations
cost O(N²) time and O(N²) memory, exhausting the heap with an
uncatchable V8 fatal error on a ~120KB payload.

Replace clone-on-write with a single mutable matrix and a
per-element undo log (restore on close), making both time and
memory linear in nesting depth. The `el.ns` proxy getter now
exposes a stable snapshot, copied on access and cached until the
matrix changes, so captured references keep their former
immutability semantics.

Ref: GHSA-6w8c-5m3c-g2m8

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nikku nikku self-assigned this Sep 21, 2026
@nikku
nikku merged commit e88354c into main Sep 21, 2026
6 checks passed
@nikku
nikku deleted the fix-namespace-declaration-dos branch September 21, 2026 06:30
pull Bot pushed a commit to Mu-L/camunda that referenced this pull request Sep 26, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [bpmn-js](https://redirect.github.com/bpmn-io/bpmn-js) | [`18.29.1` →
`18.30.1`](https://renovatebot.com/diffs/npm/bpmn-js/18.29.1/18.30.1) |
![age](https://developer.mend.io/api/mc/badges/age/npm/bpmn-js/18.30.1?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/bpmn-js/18.29.1/18.30.1?slim=true)
|
| [bpmn-js](https://redirect.github.com/bpmn-io/bpmn-js) | [`18.28.0` →
`18.30.1`](https://renovatebot.com/diffs/npm/bpmn-js/18.28.0/18.30.1) |
![age](https://developer.mend.io/api/mc/badges/age/npm/bpmn-js/18.30.1?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/bpmn-js/18.28.0/18.30.1?slim=true)
|
| [bpmn-moddle](https://redirect.github.com/bpmn-io/bpmn-moddle) |
[`10.2.0` →
`10.3.1`](https://renovatebot.com/diffs/npm/bpmn-moddle/10.2.0/10.3.1) |
![age](https://developer.mend.io/api/mc/badges/age/npm/bpmn-moddle/10.3.1?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/bpmn-moddle/10.2.0/10.3.1?slim=true)
|

---

### Release Notes

<details>
<summary>bpmn-io/bpmn-js (bpmn-js)</summary>

###
[`v18.30.1`](https://redirect.github.com/bpmn-io/bpmn-js/blob/HEAD/CHANGELOG.md#18301)

[Compare
Source](https://redirect.github.com/bpmn-io/bpmn-js/compare/v18.30.0...v18.30.1)

- `FIX`: prevent overflowing of text when layouting it
([bpmn-io/diagram-js#1106](https://redirect.github.com/bpmn-io/diagram-js/pull/1106),
[#&camunda#8203;1105](https://redirect.github.com/bpmn-io/diagram-js/pull/1105))
- `FIX`: prevent text layouting from looping in certain scenarios
([#&camunda#8203;1106](https://redirect.github.com/bpmn-io/diagram-js/pull/1106),
[bpmn-io/diagram-js#1105](https://redirect.github.com/bpmn-io/diagram-js/pull/1105))
- `DEPS`: update to `diagram-js@15.27.1`

###
[`v18.30.0`](https://redirect.github.com/bpmn-io/bpmn-js/blob/HEAD/CHANGELOG.md#18300)

[Compare
Source](https://redirect.github.com/bpmn-io/bpmn-js/compare/v18.29.1...v18.30.0)

- `FEAT`: source colors and corner radii from `@bpmn-io/theme` tokens
([#&camunda#8203;2497](https://redirect.github.com/bpmn-io/bpmn-js/pull/2497))
- `DEPS`: update to `diagram-js@15.27.0`

</details>

<details>
<summary>bpmn-io/bpmn-moddle (bpmn-moddle)</summary>

###
[`v10.3.1`](https://redirect.github.com/bpmn-io/bpmn-moddle/blob/HEAD/CHANGELOG.md#1031)

[Compare
Source](https://redirect.github.com/bpmn-io/bpmn-moddle/compare/v10.3.0...v10.3.1)

- `DEPS`: update to `moddle-xml@12.3.1`

###
[`v10.3.0`](https://redirect.github.com/bpmn-io/bpmn-moddle/blob/HEAD/CHANGELOG.md#1030)

[Compare
Source](https://redirect.github.com/bpmn-io/bpmn-moddle/compare/v10.2.0...v10.3.0)

- `FEAT`: parse documents with deeply nested namespace declarations
linearily
([nikku/saxen#33](https://redirect.github.com/nikku/saxen/pull/33))
- `DEPS`: update to `moddle-xml@12.3.0`

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
- At 08:00 PM through 11:59 PM and 12:00 AM through 08:59 AM, Monday
through Friday (`* 20-23,0-8 * * 1-5`)
  - Only on Sunday and Saturday (`* * * * 0,6`)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config
help](https://redirect.github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/camunda/camunda).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMDMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjExMi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJhcmVhL2Zyb250ZW5kIiwiYXV0b21lcmdlIiwiZGVwZW5kZW5jaWVzIl19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant